
/**
 * 
 * 服务器访问地址
 */
var forumHost = "http://www.yeeyi.com/bbs/forum.php?jsoncallback=?&mod=mobile";

/**
 * 用于分页
 */
var forumPage = 1;
var b64 = new Base64();

function xmlHttp(url,callback){
	if(url == ''){
		uexWindow.alert('参数错误','请求地址不能为空！','返回');
	}else{
		var platform = getLocalStorge('platform');
		url = url + "&pf="+platform;
		$.getJSON(url,callback);
	}
}

function  getMyThreadList(){
	uexWindow.toast("1","5","数据加载中…","0");
	var uid = getLocalStorge('uid');
	if(!uid){
		uexWindow.closeToast();
		uexWindow.alert('提示','获取失败，请先登录！','返回');
		return false;
	}
	
	forumPage = 1;
	var url = forumHost + '&ac=mythread&uid='+uid;
	xmlHttp(url,showList);
}

function showList(items){
	
	var returnCode = items[0].code;
	uexWindow.closeToast();
	if(returnCode == '404'){
		uexWindow.toast("0","5","加载失败，用户信息丢失，请先登录…","2000");
		return false;
	}
	
	var outNewsObj = $("#forum_list");
	outNewsObj.html('');
	var j = 0;
	for(var i in items){
		if(i >0 ){
			j = j + 1;
			var item = items[j];
			var tr = '';
			var trHeader = '<div ontouchstart="zy_touch(\'btn-newact\')" class="forumList" onclick="goThreadWindow('+item.tid+','+item.fid+')"><div class="ub-f1 ub ub-ver">';
			var trTitle = '<div class="title">'+b64.decode(item.subject)+'</div>';
			var trOtherInfo = '<div class="otherInfo2"><span>发布时间：'+b64.decode(item.dateline)+'</span> <span style="margin-left:1em;"> 板块： '+b64.decode(item.fname)+'</span></div>';
			var trFooter = '</div></div>';
			tr = trHeader+trTitle+trOtherInfo+trFooter;
			outNewsObj.append(tr);
		}
	}
	uexWindow.closeToast();
	
	if(j == 0){
			var tr = '';
			var trHeader = '<div ontouchstart="zy_touch(\'btn-newact\')" class="forumList"><div class="ub-f1 ub ub-ver">';
			var trTitle = '<div class="title">没找到帖子</div>';
			var trOtherInfo = '<div class="otherInfo2"><span></span> <span style="margin-left:1em;"></span></div>';
			var trFooter = '</div></div>';
			tr = trHeader+trTitle+trOtherInfo+trFooter;
			outNewsObj.append(tr);
	}
	if(j == 10){
		$('.footer').removeClass('footerHide');
	}
}

function showMoreThread(items){
	var outThreadObj = $("#forum_list");
	var j = 0;
	for(var i in items){
		if(i >0 ){
			j = j + 1;
			var item = items[j];
			var tr = '';
			var trHeader = '<div ontouchstart="zy_touch(\'btn-newact\')" class="forumList" onclick="goThreadWindow('+item.tid+','+item.fid+')"><div class="ub-f1 ub ub-ver">';
			var trTitle = '<div class="title">'+b64.decode(item.subject)+'</div>';
			var trOtherInfo = '<div class="otherInfo2"><span>发布时间：'+b64.decode(item.dateline)+'</span> <span style="margin-left:1em;"> 板块： '+b64.decode(item.fname)+'</span></div>';
			var trFooter = '</div></div>';
			tr = trHeader+trTitle+trOtherInfo+trFooter;
			outThreadObj.append(tr);
		}
	}
	uexWindow.closeToast();
	if(j == 10){
		$("#nextpage").text("查看下10条");
	}else{
		$("#nextpage").text("已经全部显示");
	}
	
}

function getMoreThread(){
	var uid = getLocalStorge('uid');
	forumPage = forumPage + 1;
	var url = forumHost + '&ac=mythread&uid='+uid+'&page='+forumPage;
	
	$("#nextpage").text("数据加载中……");
	xmlHttp(url,showMoreThread);
}

function goThreadWindow(tid,fid){
	if(tid == ''){
		uexWindow.alert("ERROR","未指定帖子ID,无法加载帖子内容！","返回");
	}else{
		
		var uid = getLocalStorge('uid');
		localStorage.setItem('authorid',uid);
		localStorage.setItem("tid",tid);
		localStorage.setItem("fid",fid);
		var threadUrl = "view_self_thread.html";
		uexWindow.open("threadWindow",0,threadUrl,2,"","",4);
	}
}

function closeWindow(){
    var closeString = "uexWindow.close(-1);";
    uexWindow.evaluateScript('', '0', closeString);
}

function getLocalStorge(key){
	var item = localStorage.getItem(key);
	if(item=='' || item==null || typeof(item)=="undefined"){
		return false;
	}else{
		return item;
	}
}